#pragma once
#ifndef xPict_h__
#define xPict_h__
#include "xRes.h"
#include "../../../dxhead/dxegheader.h"
#include "../../../xlib/xlib.h"
namespace Sky
{
	class xDxApp;
	class xPict : public xDeviceRes<LPDIRECT3DBASETEXTURE9>
	{
		friend class xCanvas;
	public:
		static TVoid StaticInit(TUint width = D3DX_DEFAULT_NONPOW2,TUint height = D3DX_DEFAULT_NONPOW2,TUint depth = D3DX_DEFAULT_NONPOW2,TUint mipLevels = D3DX_DEFAULT,TUint D3DUSAGE_ = D3DUSAGE_DYNAMIC,D3DFORMAT D3DFMT_ = D3DFMT_UNKNOWN,
			D3DPOOL D3DPOOL_ = D3DPOOL_DEFAULT,TUint filter = D3DX_DEFAULT,TUint mipFilter = D3DX_DEFAULT,D3DCOLOR colorKey = 0)
		{
			ms_Width = width;
			ms_Height = height;
			ms_Depth = depth;
			ms_MipLevels = mipLevels;
			ms_Usage = D3DUSAGE_;
			ms_Format = D3DFMT_;
			ms_Pool = D3DPOOL_;
			ms_Filter = filter;
			ms_MipFilter = mipFilter;
			ms_ColorKey = colorKey;

		}
	public:
		xPict();
		~xPict();
	protected:
		virtual TResult onCreate(xDxApp* app);
		virtual TResult onDelete(xDxApp* app);
		//xRes
		virtual TResult onCreate(xDevice* device);
		virtual TResult onReset(xDevice* device) ;
		virtual TResult onLost(xDevice* device);
		virtual TResult onDelete(xDevice* device);
	private:
		TVoid Initialise();
		TVoid Finalise();
	private:
		static const TUint From_Create	=	0x00000000;
		static const TUint From_File	=	0x00000001;
		static const TUint From_Mem		=	0x00000002;
		static const TUint From_Module	=	0x00000004;
		static const TUint From_Ex		=	0x00000008;
	public:
		static const TUint Type_Normal  =	0x10000000;
		static const TUint Type_Cube	=	0x20000000;
		static const TUint Type_Volume	=	0x40000000;
		static const TUint Type_Mask	=	0xf0000000;
	public:
		LPDIRECT3DBASETEXTURE9	getBaseTexture9(){return getCreatedRes();}
		LPDIRECT3DTEXTURE9		getNormalTexture(){return m_NormaTexture;}
		LPDIRECT3DCUBETEXTURE9	getCubeTexture(){return m_CubeTexture;}
		LPDIRECT3DVOLUMETEXTURE9 getVolumeTexture(){return m_VolumeTexture;}

		TBool isNormalTexture(){return (Type_Normal & m_Type) != 0;}
		TBool isCubeTexture(){return (Type_Cube & m_Type) != 0;}
		TBool isVolumeTexture(){return (Type_Volume & m_Type) != 0;}
		xPict& setSrcFile(Sky::StringPtr& fileName,TBool isConstStatic = vFalse);
		xPict& setSrcMem(TVoid* data,TUint size){m_srcData = data;m_srcSize = size;m_Type |= From_Mem;return *this;}
		xPict& setSrcModule(HMODULE module){m_srcModule = module; m_Type |= From_Module;return *this;}
		xPict& setType(TUint Type_){m_Type |= Type_;return *this;}

		xPict& setWidth(TUint width = D3DX_DEFAULT_NONPOW2){m_Width = width;return *this;}
		xPict& setHeight(TUint height = D3DX_DEFAULT_NONPOW2){m_Height = height;return *this;}
		xPict& setDepth(TUint depth = D3DX_DEFAULT){m_Depth = depth;return *this;}
		xPict& setMipLevel(UINT mipLevels = D3DX_DEFAULT){m_MipLevels = mipLevels;return *this;}
		xPict& setUsage(TUint usage = D3DUSAGE_DYNAMIC){m_Usage = usage; return *this;}
		xPict& setFormat(D3DFORMAT D3DFMT_ = D3DFMT_UNKNOWN){m_Format = D3DFMT_; return *this;}
		xPict& setPool(D3DPOOL D3DPOOL_ = D3DPOOL_DEFAULT){m_Pool = D3DPOOL_; return *this;}
		xPict& setFilter(TUint filter = D3DX_DEFAULT){m_Filter = filter;m_Type |= From_Ex;return *this;}
		xPict& setMipFilter(TUint mipFilter = D3DX_DEFAULT){m_MipFilter = mipFilter;m_Type |= From_Ex; return *this;}
		xPict& setColorKey(D3DCOLOR ColorKey = 0){m_ColorKey = ColorKey;m_Type |= From_Ex; return *this;}
		xPict& setGetSrcInfo(TBool bGet = vFalse){if(bGet)m_Type |= From_Ex;return *this;}
		TUint  getUsage(){return m_Usage;}

		TInt getWidth(){return m_Width;}
		TInt getHeight(){return m_Height;}
	private:
		static TInt ms_Width;
		static TInt ms_Height;
		static TInt ms_Depth;
		static TUint ms_MipLevels;
		static TUint ms_Usage;
		static D3DFORMAT ms_Format;
		static D3DPOOL ms_Pool;
		static TUint ms_Filter;
		static TUint ms_MipFilter;
		static D3DCOLOR ms_ColorKey;
	
	private:
		LPDIRECT3DTEXTURE9	m_NormaTexture;
		LPDIRECT3DCUBETEXTURE9 m_CubeTexture;
		LPDIRECT3DVOLUMETEXTURE9 m_VolumeTexture;

		TUint	 m_Type;
		StringPtr m_srcFile;
		TVoid*	 m_srcData;
		TUint	 m_srcSize;
		HMODULE	 m_srcModule;

		D3DXIMAGE_INFO m_srcInfo;
		TInt m_Width;
		TInt m_Height;
		TInt m_Depth;
		TUint m_MipLevels;
		TUint m_Usage;
		D3DFORMAT m_Format;
		D3DPOOL m_Pool;
		TUint m_Filter;
		TUint m_MipFilter;
		D3DCOLOR m_ColorKey;
	};

}
#endif // xPict_h__